//
//  ViewController.m
//  OatosMacDemo
//
//  Created by 李少游 on 2017/3/24.
//
//

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController()
{
    NSArray * _dataArray;
}

@end


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _myTableView.frame = self.view.bounds;
    [NSFileManager defaultManager];
    _dataArray = @[@"testrtf.rtf",@"2015斤斤计较解放军绝对是发送到方式.pptx",@"软件企业证书副本.pdf",@"OATOS服务条款2012-9-4.doc",@"OATOS服务条款更新记录.xlsx",@"123.txt"];
    
    
}

#pragma mark-NSTableViewDataSource
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
    return _dataArray.count;
}

- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row NS_AVAILABLE_MAC(10_7){
    NSTableCellView *cell = [tableView makeViewWithIdentifier:@"mycell" owner:self];
    cell.textField.stringValue = _dataArray[row];
    return cell;
}

#pragma mark - NSTableViewDelegate
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row{
    NSLog(@"shouldSelectRow");
    NSString *file = _dataArray[row];
    NSArray *fileInfo = [file componentsSeparatedByString:@"."];
    NSString *fileName = [fileInfo firstObject];
    

    NSString *path= [[NSBundle mainBundle] pathForResource:fileName ofType:[fileInfo lastObject]];
    
    NSURL *fileUrl = [NSURL fileURLWithPath:path];
    [[NSWorkspace sharedWorkspace]openURL:fileUrl];
    return YES;
}
- (void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn{
    NSLog(@"didClickTableColumn");
}
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row{
    return  50;
}

@end
